package com.ruoyi.web.controller.shopweb;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ShopDemand;
import com.ruoyi.system.service.IShopDemandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 需求信息Controller
 * 
 * @author ruoyi
 * @date 2024-06-03
 */
@RestController
@RequestMapping("/system/demand")
public class ShopDemandController extends BaseController
{
    @Autowired
    private IShopDemandService shopDemandService;

    /**
     * 查询需求信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:demand:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopDemand shopDemand)
    {
        startPage();
        List<ShopDemand> list = shopDemandService.selectShopDemandList(shopDemand);
        return getDataTable(list);
    }

    /**
     * 导出需求信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:demand:export')")
    @Log(title = "需求信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopDemand shopDemand)
    {
        List<ShopDemand> list = shopDemandService.selectShopDemandList(shopDemand);
        ExcelUtil<ShopDemand> util = new ExcelUtil<ShopDemand>(ShopDemand.class);
        util.exportExcel(response, list, "需求信息数据");
    }

    /**
     * 获取需求信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:demand:query')")
    @GetMapping(value = "/{demandId}")
    public AjaxResult getInfo(@PathVariable("demandId") Long demandId)
    {
        return success(shopDemandService.selectShopDemandByDemandId(demandId));
    }

    /**
     * 新增需求信息
     */
    @PreAuthorize("@ss.hasPermi('system:demand:add')")
    @Log(title = "需求信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopDemand shopDemand)
    {
        return toAjax(shopDemandService.insertShopDemand(shopDemand));
    }

    /**
     * 修改需求信息
     */
    @PreAuthorize("@ss.hasPermi('system:demand:edit')")
    @Log(title = "需求信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopDemand shopDemand)
    {
        return toAjax(shopDemandService.updateShopDemand(shopDemand));
    }

    /**
     * 删除需求信息
     */
    @PreAuthorize("@ss.hasPermi('system:demand:remove')")
    @Log(title = "需求信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{demandIds}")
    public AjaxResult remove(@PathVariable Long[] demandIds)
    {
        return toAjax(shopDemandService.deleteShopDemandByDemandIds(demandIds));
    }
}
